#include "precomp.h"
#include "DisplayObject.h"


DisplayObject::DisplayObject(void)
{
	velocity.x = 0.0f; velocity.y = 0.0f;
	accelerator = 0.0f;
	currentSize.height = currentSprite->get_height();
	currentSize.width = currentSprite->get_width();
	currentPos = CL_Pointf(0,0);
	radian = 0.0f;
}


DisplayObject::~DisplayObject(void)
{
	delete standSprite;
}

float &DisplayObject::getAccelerator()
{
	return accelerator;
}
void DisplayObject::setAccelerator(float newAccelerator)
{
	accelerator = newAccelerator;
}

CL_Vec2f &DisplayObject::getVelocity()
{
	return velocity;
}
void DisplayObject::setVelocity(CL_Vec2f newVelocity)
{
	velocity = newVelocity;
}

CL_Pointf &DisplayObject::getPos()
{
	return currentPos;
}
void DisplayObject::setPos(CL_Pointf setPosition)
{
	currentPos = setPosition;
}

CL_Colorf &DisplayObject::getColor()
{
	return currentColor;
}
void DisplayObject::setColor(CL_Colorf colorRGBA)
{
	currentColor = colorRGBA;
}

void DisplayObject::setStandSprite(CL_GraphicContext &gc, const CL_StringRef name, CL_ImageImportDescription &importDesc)
{
	if(standSprite!=NULL)
	{
		trashSprite.push_back(standSprite);
	}
	CL_Sprite *newSprite = new CL_Sprite(gc,name,importDesc);
	standSprite = newSprite;
}

void DisplayObject::updateVelocity(unsigned int time)
{
	velocity = velocity * accelerator * time;
}

void DisplayObject::updatePosition(unsigned int time)
{
	currentPos.x = currentPos.x + velocity.x*time;
	currentPos.y = currentPos.y + velocity.y*time;
	updateVelocity(time);
}

void DisplayObject::run(CL_GraphicContext &gc, unsigned int time)
{
	updatePosition(time);
	currentSprite->update();
	currentSprite->rotate(CL_Angle::from_radians(radian));
	currentSprite->draw(gc,CL_Rectf(currentPos,currentSize));
}